<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="tools.DataSet" import="java.util.*" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>查询页面</title>
<style>
body{
	
	font-family:"Arial Unicode MS", monospace, "微软雅黑";
	font-size:20px;
	
}
.select1{
	width:126px; 
	height:28px; 
	font-size:20px;
}
</style>
<script type="text/javascript">
	//刷新页面函数
	function refresh(obj){
		var form=document.getElementById("inquireForm");
		form.action="QueryMsgServlet?update";
		form.submit();
	}
	//展开函数
	function unFade(id){
		var form=document.getElementById("inquireForm");
		form.action="QueryMsgServlet?"+id;
		form.submit();
	}
	//折叠函数
	function Fade(){
		var form=document.getElementById("inquireForm");
		form.action="QueryMsgServlet?fade";
		form.submit();
	}
	//年龄input，”输入数字“文字隐藏/显示
	function $(str){ return(document.getElementById(str)); }
	function mover(){
        event.srcElement.focus();
        event.srcElement.select();
    }
	function mclick(){
        if(event.srcElement.value=="输入数字")event.srcElement.value="";
    }
    function mblur(){
        if(event.srcElement.value=="")event.srcElement.value="输入数字";
    }
	
	//验证数据
	//年龄输入值为数字验证
	var REG_VALIDATE = new Array();
	REG_VALIDATE["age"] = /1\d{2}|[1-9]\d?/;//年龄正则表达式
	
	function check_submit(){
        if($("age").value==""){ alert("请填年龄"); return(false); }
		if(paresInt($("age").value)!= REG_VALIDATE["age"]){alert("年龄段：请输入数字，范围：0-199");return (false);}
    }
	
	//图片加号点击显示新增一条查询条件
		 //不知道如何做成循环的显示，求大神谅解
		 function blockDiv1() {
	 //显示层
            var div = document.getElementById("checks").style.display; 
			if (div == 'none') {
                document.getElementById("checks").style.display = 'block';
            } 
        }
		
		function blockDiv2() {
	 //显示层
            var div = document.getElementById("test_add").style.display; 
			if (div == 'none') {
                document.getElementById("test_add").style.display = 'block';
            } 
        }
					
			


</script>
</head>

<body >
<div align="center">

<form name="inquireForm" action="QueryMsgServlet" method="post">
<%
	//声明数据包
	DataSet ds=new DataSet();
	String JDBC_DRIVER="com.mysql.jdbc.Driver";
	String DB_URL="jdbc:mysql://localhost:3306/MedicalServiceSystem?useUnicode=true&characterEncoding=utf8";
	String dbUser="soft";
	String dbPwd="123456";
%>
	<div id="shaixuan" align="center">
	<table border="1">
	<tr>
	<td>
	
	
	<table style="width:900px; height:45px; " border="0">
		<tr><td align="left">
			<label style="background-color:#E4E4E4; font-size:24px;" >筛选</label>
			
		</td></tr>
		<tr><td height="36" align="left">
			<div id="sx_sex" >
			性别：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<%
				String sex=request.getParameter("sex");
			%>
				<input id="sex1" name="sex" type="radio" value="男" <%if(sex!=null&&sex.equals("男"))out.println("checked=\"checked\""); %>> 男 &nbsp;&nbsp;&nbsp;
				<input id="sex2" name="sex" type="radio" value="女" <%if(sex!=null&&sex.equals("女"))out.println("checked=\"checked\""); %>> 女 &nbsp;&nbsp;&nbsp;
				<input id="sex3" name="sex" type="radio" value="不限" <%if(sex!=null&&sex.equals("不限"))out.println("checked=\"checked\""); %>> 不限			</div>
				
		</td></tr>
		<tr><td align="left">
			<div id="sx_age" >
				年龄段：
			&nbsp;&nbsp;&nbsp;
			<%
				String age=request.getParameter("age");
			%>
			<input id="age" name="age" type="text"   value=<%
				if(age!=null){
					age="\""+age+"\"";
					out.println(age);
				}else{
					out.println("输入数字");
				}
			%> style="width:97px; height:32px; font-size:18px;" onMouseOver="mover()" onClick="mclick()" onBlur="mblur()"  >
			</div>
			
		</td></tr>
		<tr><td align="left">
			<div id="sx_DeskWork" >
			<!--
			所有下拉框：可以通过输入几个文字检索出选择项，不会做，没做；请大神谅解。
			-->
				科室：
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<select id="keshi" name="keshi" size="1" class="select1" >
                  <option id="selectname1" class="select1" style="width:126px" selected>不限</option>
                  <option id="selectname2" class="select1">眼科</option>
                  <option id="selectname3"  class="select1">科室二</option>
                </select>
			</div>
			
		</td></tr>
		<tr><td align="left">
		
		<!--检查指标显示-->
			<div id="sx_Check" >
			检查指标：
			<select id="Checks1" name="Checks1" size="1" style="width:250px; height:28px; font-size:20px;" >
			  
			  <%
			  	String ITEM_NAME=request.getParameter("Checks1");
			  	String cmd="select distinct(ITEM_NAME)as ITEM_NAME from TESTAPPLY;";
			  	List<String> slis=ds.QueryStrings(cmd,"ITEM_NAME");
			  	if(ITEM_NAME!=null){
			  		String head=slis.get(0);
			  		slis.set(slis.indexOf(ITEM_NAME),head);
			  		slis.set(0,ITEM_NAME);
			  	}
			  	for(int i=0;i<slis.size();i++){
			  		String option="<option id=\"Checks1_"+i+"\" style=\"width:250px\">"+slis.get(i)+"</option>";
			  		out.println(option);
			  	}
			  %>
			</select>
			<select id="choice" name="choice" size="1" style="width:60px; height:28px; font-size:20px;">
			<%
				String choice=request.getParameter("choice");
				if(choice!=null){
					out.println("<option id=\"choice_0\" style=\"width:60px\" value=\""+choice+"\">"+choice+"</option>");
				}
			%>
			  <option id="choice_1" style="width:60px" value="或者">或者</option>
			  <option id="choice_2" style="width:60px" value="和">和</option>
			  <option id="choice_3" style="width:60px" value="除了">除了</option>
			</select>
			<select id="checks2" name="checks2" size="1" style="width:250px; height:28px; font-size:20px;">
			  <%
			  	ITEM_NAME=request.getParameter("checks2");
			  	if(ITEM_NAME!=null){
			  		String head=slis.get(0);
			  		slis.set(slis.indexOf(ITEM_NAME),head);
			  		slis.set(0,ITEM_NAME);
			  	}
			  	for(int i=0;i<slis.size();i++){
			  		String option="<option id=\"Checks2_"+i+"\" style=\"width:250px\">"+slis.get(i)+"</option>";
			  		out.println(option);
			  	}
			  %>
			</select>
			&nbsp;&nbsp;
			<input id="input_add_check" name="Input" type="button" style="background-image:url(Resource/Image/little_add.png); width:20px; height:20px; position:absolute; left: 870px; top: 170px;" value="" onClick="blockDiv1()">
			</div>
			
			
			<!--检查指标隐藏的层，点击加号显示-->
			<div id="checks" style="display:none;">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<select id="Checks1" name="Checks1" size="1" style="width:250px; height:28px; font-size:20px;" >
			  <option id="Checks1_1" style="width:250px">X线透视检查</option>
			</select>
			<select id="choice" name="choice" size="1" style="width:60px; height:28px; font-size:20px;">
			<%
				choice=request.getParameter("choice");
				if(choice!=null){
					out.println("<option id=\"choice_0\" style=\"width:60px\" value=\""+choice+"\">"+choice+"</option>");
				}
			%>
			  <option id="choice_1" style="width:60px" value="或者">或者</option>
			  <option id="choice_2" style="width:60px" value="和">和</option>
			  <option id="choice_3" style="width:60px" value="除了">除了</option>
			</select>
			<select id="checks2" name="checks2" size="1" style="width:250px; height:28px; font-size:20px;">
			  <option id="checks2_1" style="width:250px">唾液腺造影</option>
			</select>
			&nbsp;&nbsp;
			</div>
			
		</td></tr>
		<tr><td align="left">
		
		<!--显示检验指标的层-->
			<div id="sx_Test" >
				检验指标：
				<select id="test" name="test" size="1" style="width:250px; height:28px; font-size:20px;" onchange="refresh(this);">
					<%
					String EXAM_CLASS=request.getParameter("test");
					cmd="select distinct(EXAM_CLASS)as EXAM_CLASS from EXAMAPPLY";
					slis=ds.QueryStrings(cmd,"EXAM_CLASS");
				  	if(EXAM_CLASS!=null){
				  		String head=slis.get(0);
				  		slis.set(slis.indexOf(EXAM_CLASS),head);
				  		slis.set(0,EXAM_CLASS);
				  	}
					for(int i=0;i<slis.size();i++){
						String option="<option id=\"test1_"+i+"\" style=\"width:250px\">"+slis.get(i)+"</option>";
						out.println(option);
					}
					%>
			    </select>
				<select id="tset2" name="test2" size="1" style="width:80px; height:28px; font-size:20px;">
				  <%
				  	if(EXAM_CLASS==null){
				  		cmd="select distinct(EXAM_SUB_CLASS)as EXAM_SUB_CLASS from EXAMAPPLY,(select distinct(EXAM_CLASS)as EXAM_CLASS from EXAMAPPLY limit 1)as ec where ec.EXAM_CLASS=EXAMAPPLY.EXAM_CLASS;";
				  	}else{
				  		cmd="select distinct(EXAM_SUB_CLASS)as EXAM_SUB_CLASS from EXAMAPPLY where EXAM_CLASS=\""+EXAM_CLASS+"\";";
				  	}
				  	slis=ds.QueryStrings(cmd,"EXAM_SUB_CLASS");
				  	for(int i=0;i<slis.size();i++){
						String option="<option id=\"test2_"+i+"\" style=\"width:250px\">"+slis.get(i)+"</option>";
						out.println(option);
					}
				  %>
			    </select>
				<select id="test3" name="test3" size="1" style="width:60px; height:28px; font-size:20px;">
				<%
					String test3=request.getParameter("test3");
					if(test3!=null){
						out.println("<option id=\"choice_0\" style=\"width:60px\" value=\""+test3+"\">"+test3+"</option>");
					}
				%>
				  <option id="choice_1" style="width:60px" value="或者">或者</option>
				  <option id="choice_2" style="width:60px" value="和">和</option>
				  <option id="choice_3" style="width:60px" value="除了">除了</option>
			    </select>
				<select id="test4" name="test4" size="1" style="width:250px; height:28px; font-size:20px;" onchange="refresh(this);">
				  	<%
				  	EXAM_CLASS=request.getParameter("test4");
					cmd="select distinct(EXAM_CLASS)as EXAM_CLASS from EXAMAPPLY";
					slis=ds.QueryStrings(cmd,"EXAM_CLASS");
				  	if(EXAM_CLASS!=null){
				  		String head=slis.get(0);
				  		slis.set(slis.indexOf(EXAM_CLASS),head);
				  		slis.set(0,EXAM_CLASS);
				  	}
					for(int i=0;i<slis.size();i++){
						String option="<option id=\"test4_"+i+"\" style=\"width:250px\">"+slis.get(i)+"</option>";
						out.println(option);
					}
					%>
			    </select>
				<select id="test5" name="test5" size="1" style="width:80px; height:28px; font-size:20px;">
				  <%
				  	if(EXAM_CLASS==null){
				  		cmd="select distinct(EXAM_SUB_CLASS)as EXAM_SUB_CLASS from EXAMAPPLY,(select distinct(EXAM_CLASS)as EXAM_CLASS from EXAMAPPLY limit 1)as ec where ec.EXAM_CLASS=EXAMAPPLY.EXAM_CLASS;";
				  	}else{
				  		cmd="select distinct(EXAM_SUB_CLASS)as EXAM_SUB_CLASS from EXAMAPPLY where EXAM_CLASS=\""+EXAM_CLASS+"\";";
				  	}
				  	slis=ds.QueryStrings(cmd,"EXAM_SUB_CLASS");
				  	for(int i=0;i<slis.size();i++){
						String option="<option id=\"test5_"+i+"\" style=\"width:250px\">"+slis.get(i)+"</option>";
						out.println(option);
					}
				  %>
			    </select>
				&nbsp;
				<input id="input_add_test" name="add1" type="button" style="background-image:url(Resource/Image/little_add.png); width:20px; height:20px; position:absolute; left: 1030px; top: 205px;" value="" onClick="blockDiv2()">
			</div>
			
			<!--隐藏的检验指标的层，点击加号显示-->
			<div id="test_add" style="display:none" >
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<select id="test" name="test" size="1" style="width:250px; height:28px; font-size:20px;">
				  <option id="test_1" style="width:250px">血液学检查/血液一般形态检查</option>
			    </select>
				<select id="tset2" name="test2" size="1" style="width:80px; height:28px; font-size:20px;">
				  <option id="test2_1" style="width:80px">白细胞</option>
			    </select>
				<select id="test3" name="test3" size="1" style="width:60px; height:28px; font-size:20px;">
				<%
					test3=request.getParameter("test3");
					if(test3!=null){
						out.println("<option id=\"choice_0\" style=\"width:60px\" value=\""+test3+"\">"+test3+"</option>");
					}
				%>
				  <option id="choice_1" style="width:60px" value="或者">或者</option>
				  <option id="choice_2" style="width:60px" value="和">和</option>
				  <option id="choice_3" style="width:60px" value="除了">除了</option>
			    </select>
			    </select>
				<select id="test4" name="test4" size="1" style="width:250px; height:28px; font-size:20px;">
				  <option id="test4_1" style="width:250px">血液学检查/血凝、纤溶相关检查</option>
			    </select>
				<select id="test5" name="test5" size="1" style="width:80px; height:28px; font-size:20px;">
				  <option id="test5_1" style="width:80px">血红蛋白</option>
			    </select>
				&nbsp;
				
			</div>
			
		</td></tr>
		<tr><td align="right">
		<input id="sx_Submit" name="sx_Submit"  type="submit" value="查询 " onClick="check_submit()" style="width:132px; height:48px; font-size:20px; background-color:#0099FF; font-size:24px; "></td></tr>
	</table>
	</td>
	</tr>
	</table>
	</div>
	<br/>
	<br/>
	<div id="cx_show">
		<table width="900" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col">编号</th>
    <th scope="col">姓名</th>
    <th scope="col">性别</th>
    <th scope="col">住院次数</th>
    <th scope="col">影像ID</th>
    <th scope="col">住院号</th>
    <th scope="col">临床诊断</th>
    <th scope="col">展开/收缩</th>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <%
  	Object obj=request.getAttribute("cmd");
  	Object idobj=request.getAttribute("pid");
  	if(obj!=null&&idobj==null){
  		cmd=obj.toString();
		java.sql.Connection con=null;
		java.sql.Statement stat=null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con=DriverManager.getConnection(DB_URL, dbUser, dbPwd);
			stat=con.createStatement();
			ResultSet res=stat.executeQuery(cmd);
			while(res.next()){
				String pid=res.getString("PATIENT_ID");
				String np=res.getString("NAME_PHONETIC");
				sex=res.getString("SEX");
				age=res.getString("AGE");
				String adm=res.getString("ADMISSION");
				String tno=res.getString("TEST_NO");
				String rgd=res.getString("CLIN_DIAG");
				String vid=res.getString("VISIT_ID");
				String tab="<tr>"+
				    "<td>"+pid+"</td>"+
				    "<td>"+np+"</td>"+
				    "<td>"+sex+"</td>"+
				    "<td>"+adm+"</td>"+
				    "<td>"+tno+"</td>"+
				    "<td>"+vid+"</td>"+
				    "<td>"+rgd+"</td>"+
				    "<td><input type='button' value='展开' onClick=\"unFade('"+pid+"')\"/></td></tr>";
				out.println(tab);
			}
			res.close();
			stat.close();
			con.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  	}else if(idobj!=null){
  		String id=idobj.toString();
  		cmd="SELECT * FROM MEDICAL WHERE PATIENT_ID='"+id+"' ORDER BY EXECUTE_DATE DESC;";
  		java.sql.Connection con=null;
		java.sql.Statement stat=null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con=DriverManager.getConnection(DB_URL, dbUser, dbPwd);
			stat=con.createStatement();
			ResultSet res=stat.executeQuery(cmd);
			while(res.next()){
				String pid=res.getString("PATIENT_ID");
				String np=res.getString("NAME_PHONETIC");
				sex=res.getString("SEX");
				age=res.getString("AGE");
				//String adm=res.getString("admission");
				String tno=res.getString("TEST_NO");
				String rgd=res.getString("RELEVANT_CLINIC_DIAG");
				String vid=res.getString("VISIT_ID");
				String tab="<tr>"+
				    "<td>"+pid+"</td>"+
				    "<td>"+np+"</td>"+
				    "<td>"+sex+"</td>"+
				    "<td>-</td>"+
				    "<td>"+tno+"</td>"+
				    "<td>"+vid+"</td>"+
				    "<td>"+rgd+"</td>"+
				    "<td><input type='button' value='折叠' onClick='Fade();'/></td></tr>";
				out.println(tab);
			}
			res.close();
			stat.close();
			con.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  	}
  %>
  <tr><td colspan="7">
  	<div align="center"> 
		<input name="" type="button" value="上一页" onClick=""> 
		<input name="" type="button" value="1" onClick=""> 
		<input name="" type="button" value="2" onClick=""> 
		<input name="" type="button" value="3" onClick=""> 
		<input name="" type="button" value="..." onClick="" style="width:30px"> 
		<input name="" type="button" value="下一页"onClick=""> 
	</div>
  </td></tr>
</table>

	</div>

</form>
</div>
</body>

</html>